# @file    : pipeline_test
# @time    : 2025/3/21
# @author  : yongpeng.yao
# @desc    :
import os

from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI

os.environ['DASHSCOPE_API_KEY'] = "sk-279c68899b4b4b12abf531d1d42a1572"
# 创建一个聊天提示模板，其中{topic}是占位符，用于后续插入具体的话题
prompt = ChatPromptTemplate.from_template('请将一个关于{topic}的故事')
model = ChatOpenAI(
    model='deepseek-r1',
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"
)

output_parser = StrOutputParser()
# 通过管道操作符(|)连接各个处理步骤，以创造一个完整的处理链
chain = prompt | model | output_parser
message = chain.invoke({"topic": "水仙花"})
print(message)
